
 
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
 
// annotations tells that this is an entity
// which should be persisted
@Entity
// table name have to be changed to "users"
// it should be "users" because keyword "user" is restricted in PostgreSQL
@Table(name = "users")
public class User {
 
  public static final String FIELD_ID = "id";
  public static final String FIELD_NAME = "name";
  public static final String FIELD_AGE = "age";
 
  // this field is primary key and its value have to be generated using
  // strategy
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private int id;
 
  // this field in db have to be unique
  @Column(unique = true)
  private String name;
  private int age;
 
  public int getId() {
    return id;
  }
 
  protected void setId(int id) {
    this.id = id;
  }
 
  public String getName() {
    return name;
  }
 
  public void setName(String name) {
    this.name = name;
  }
 
  public int getAge() {
    return age;
  }
 
  public void setAge(int age) {
    this.age = age;
  }
 
}